package com.twu.biblioteca;

/**
 * Created with IntelliJ IDEA.
 * User: PREETHI
 * Date: 26/5/13
 * Time: 10:10 PM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
public class MovieManager {
    Scanner scan=new Scanner(System.in);
    public movieList movielist;
    public MovieManager(movieList movielist) {

         this.movielist=movielist;
    }

    public void respond(int index,user loggedInUser) {

        if(index==3)
           System.out.println(  viewMovies());
        else if(index==4&& loggedInUser!=null)
        {
             System.out.println("Enter the Movie Name:");
            String movieName=null;
             movieName=scan.next();
            reserveMovies(movieName);

        }
        else
            System.out.println(MESSAGES.LOGIN_TO_RESERVE);

    }

    public void reserveMovies(String movieName) {

        boolean reserved=false;
        for(movie m: movielist.getMovieList())
        {
            if(m.getMovieName().equals(movieName)&&m.getQuantity()>0)
            {


                    System.out.println(MESSAGES.MOVIE_RESERVATION_SUCCESSFUL);
                    reserved=true;
            }
        }
        if(reserved==false)
            System.out.println(MESSAGES.MOVIE_RESERVATION_UNSUCCESSFUL);
    }

    public String viewMovies() {
       String display;
        display="Movie Name\tMovie Year\tDirector\tRating\n";
        for(movie m:movielist.getMovieList())
        {
           display+=m.getMovieName()+"\t"+m.getYear()+"\t"+m.getDirector()+"\t"+m.getRating()+"\n";


        }
        return  display;
    }
}
